package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseManageService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品基础属性接口")
@RestController
@RequestMapping("/admin/product")
public class BaseManageController {

    @Autowired
    private BaseManageService baseManageService;

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

    // /admin/product/getCategory1
    // 查询1级分类数据
    @GetMapping("/getCategory1")
    public Result getCategory1(){
        //调用service
        List<BaseCategory1> baseCategory1List = baseManageService.getCategory1();
        //返回结果
        return Result.ok(baseCategory1List);
    }

    // 查询2级分类数据
    //  /admin/product/getCategory2/{category1Id}
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id){
        List<BaseCategory2> baseCategory2List = baseManageService.getCategory2(category1Id);
        return Result.ok(baseCategory2List);
    }

    // 根据二级id查询三级分类数据
    // /admin/product/getCategory3/{category2Id}
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id){
        List<BaseCategory3> baseCategory3List = baseManageService.getCategory3(category2Id);
        return Result.ok(baseCategory3List);
    }

    // /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
    // 根据分类id查询分类属性集合及分类属性值
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result selectAttrInfoList(@PathVariable Long category1Id,
                                      @PathVariable Long category2Id,
                                      @PathVariable Long category3Id){
        List<BaseAttrInfo> baseAttrInfoList = baseAttrInfoService.selectAttrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(baseAttrInfoList);
    }

    // /admin/product/saveAttrInfo
    // 保存修改平台属性
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        //调用service，添加数据
        baseAttrInfoService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    // 修改数据回显
    // /admin/product/getAttrValueList/{attrId}
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){

        // 调用service层
        List<BaseAttrValue> list = baseManageService.getAttrValueList(attrId);
        return Result.ok(list);
    }


}
